<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      text-decoration: none;
      list-style: none;
    }

    ul {
      display: flex;
    }

    li {
      flex-basis: 20%;
      text-align: center;
      line-height: 50px;
      border: 2px solid pink;
      color: rosybrown;
    }

    li.active {
      background-color: seagreen;
      color: #fff;
    }

    main {
      position: relative;
    }

    section {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 200px;
      text-align: center;
      line-height: 200px;
      opacity: 0;
      z-index: 0;
      transition: all 3s;
    }

    section.active {
      opacity: 1;
      z-index: 10;
    }
  </style>
</head>

<body>
  <div>
    <ul>
      <li class="active">哈哈哈1</li>
      <li>哈哈哈2</li>
      <li>哈哈哈3</li>
      <li>哈哈哈4</li>
      <li>哈哈哈5</li>
    </ul>

    <main>
      <section class="active" style="background-color: orange;">我是内容01</section>
      <section style="background-color: yellow;">我是内容02</section>
      <section style="background-color: green;">我是内容03</section>
      <section style="background-color: purple">我是内容04</section>
      <section style="background-color: blue">我是内容05</section>
    </main>
  </div>
  <script>
    let lis = document.querySelectorAll("ul li")
    let sections = document.querySelectorAll("section")
    let lastindex = 0;
    lis.forEach((item, index) => {
      item.addEventListener("click", function () {
        // console.log(`我是第${index}个li`);
        lis[lastindex].classList.remove("active");
        lis[index].classList.add("active");

        sections[lastindex].classList.remove("active");
        sections[index].classList.add("active");
        lastindex = index;

      })

    })
  </script>
</body>

</html>